package com.comtime.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;

import com.comtime.smartkilimanjaro.R;

public class MySharedPreferences {
	private static Context mContext;
	private SharedPreferences.Editor editor;
	private SharedPreferences preferences;
	private final String ONE_NAME = "one";
	private final String TWO_NAME = "two";
	private final String THREE_NAME = "three";
	private final String aLLNAMEString = "allname";
 


//	public static MySharedPreferences getInstance(Context context, int select_tag) {
//		
//		return new MySharedPreferences(context,select_tag);
//	}

	public static MySharedPreferences getInstance(Context context) {
		
		return new MySharedPreferences(context);
	}

	private MySharedPreferences(Context context) {
		mContext = context;
		
			preferences = mContext.getSharedPreferences(aLLNAMEString, 0);
		
		editor = preferences.edit();
	}
   
	/**
	 * private
	 */
	private MySharedPreferences(Context context,int tag) {
		mContext = context;
		if (tag==0) {
			preferences = mContext.getSharedPreferences(ONE_NAME, 0);
		}else if (tag==1) {
			preferences = mContext.getSharedPreferences(TWO_NAME, 0);
		}else {
			preferences = mContext.getSharedPreferences(THREE_NAME, 0);
		}
		editor = preferences.edit();
	}
	
	/**
	 * 下载apk
	 * @return
	 */
	public  String getAPKUrl(){
		return preferences.getString("APKUrl", "");
		
	}
	public void saveAPKUrl(String str){
		editor.putString("APKUrl", str);
		editor.commit();
	}
	
	
	public void saveBluAdress(String str){
		Log.e("tag", "myshare str:"+str);
		editor.putString("BluAdress", str);
		editor.commit();
	}
	public String getBluAdress() {
		return preferences.getString("BluAdress", "");
	}
	
	/**
	 * battery
	 */
	public void saveBattery(int str){
		editor.putInt("battery", str);
		editor.commit();
	}
	public int getBattery(){
		return preferences.getInt("battery",0);
	}
	
	
	
	public void saveIsFirstUse(boolean flag) {
		editor.putBoolean("IsFirstUse", flag);
		editor.commit();
	} 

	public boolean getIsFirstUse() {
		return preferences.getBoolean("IsFirstUse", true);
	}

	

	public void saveIsLogined(boolean flag) {
		editor.putBoolean("IsLogined", flag);
		editor.commit();
	} 

	public boolean getIsLogined() {
		return preferences.getBoolean("IsLogined", false);
	}

	/**
	 * user phonenum
	 */
	public void savePhoneNum(String phoneNum){
		editor.putString("LoginPhoneNum", phoneNum);
		editor.commit();
	}
	public String getPhoneNum(){
		return preferences.getString("LoginPhoneNum", "");
	}
	/**
	 * user pwd
	 */
	public void savePasswd(String phoneNum){
		editor.putString("Passwd", phoneNum);
		editor.commit();
	}
	public String getPasswd(){
		return preferences.getString("Passwd", "");
	}
	/**
	 * headUrl
	 */
	public void saveUserLoginHeadURL(String headUrl){
		editor.putString("LoginHeadURL", headUrl);
		editor.commit();
	}
	public String getUserLoginHeadURL(){
		return preferences.getString("LoginHeadURL", "");
	}
	
	/**
	 * name
	 */
	public void saveUserName(String headUrl){
		editor.putString("UserName", headUrl);
		editor.commit();
	}
	public String getUserName(){
		return preferences.getString("UserName", "");
	}
	
	/**
	 * sex
	 */
	public void saveUserSex(int sex){
		editor.putInt("sex", sex);
		editor.commit();
	}
	public int getUserSex(){
		return preferences.getInt("sex", 0);
	}
	
	/**
	 * userId
	 */
	public void saveUserId(int UserId){
		editor.putInt("UserId", UserId);
		editor.commit();
	}
	public int getUserId(){
		return preferences.getInt("UserId", -1);
		
	}
	
	
	/**
	 * 选择报警音乐用到
	 * @param num
	 */
	public void saveCustomRecordNum(int num) {
		editor.putInt("CustomRecordNum", num);
		editor.commit();
	}
	public int getCustomRecordNum() {
		return preferences.getInt("CustomRecordNum", 0);// 
	}
	/**
	 * token
	 */
	public void saveToken(String token){
		editor.putString("token", token);
		editor.commit();
	}
	public String getToken(){
		return  preferences.getString("token", "");
	}
	
	/**
	 * status
	 */
	public void saveVerStatus(int status){
		editor.putInt("status", status);
		editor.commit();
	}
	public int getVerStatus(){
		return preferences.getInt("status", 0);
	}
	
	/**
	 * create time
	 */
	public void saveCreateTime(String token){
		editor.putString("createtime", token);
		editor.commit();
	}
	public String getCreateTime(){
		return  preferences.getString("createtime", "");
	}

	/**
	 * device disconnect time
	 * 设备断开连接时间
	 * @param time
	 */
	public void saveDisconnectDeviceTime(long time){
		editor.putLong("DisconnectDeviceTime", time);
		editor.commit();
	}
	public long getDisconnectDeviceTime(){
		return preferences.getLong("DisconnectDeviceTime", 0);
	}
	

	/***************************************low battery function***********************************************/
	
	/**
	 * 低电量报警音乐路径
	 * @return
	 */
	public void saveLowBatteryWainVoicePath(String str){
		editor.putString("LowBatteryWainVoicePath", str);
		editor.commit();
	}
	public String getLowBatteryWainVoicePath(){
		return preferences.getString("LowBatteryWainVoicePath","android.resource://" + mContext. getPackageName()
				+ "/" + R.raw.dog);
		
	}
	
	/**
	 * 低电量报警音乐名字
	 * @return
	 */
	public void saveLowBatteryWainVoiceTitle(String str){
		editor.putString("LowBatteryWainVoiceTitle", str);
		editor.commit();
	}
	public String getLowBatteryWainVoiceTitle(){
		return preferences.getString("LowBatteryWainVoiceTitle", mContext.getString(R.string.default_music));
		
	}
	/**
	 * low battery wain function
	 * 低电量提醒开关
	 */
	public void saveLowBatteryWain(boolean b){
		editor.putBoolean("LowBatteryWain", b);
		editor.commit();
	}
	public boolean getLowBatteryWain(){
		return preferences.getBoolean("LowBatteryWain", true);
	}
	
	
	
	/**
	 *  
	 * 低电量提醒震动开关
	 */
	public void saveLowBatteryVibrate(boolean b){
		editor.putBoolean("LowBatteryVibrate", b);
		editor.commit();
	}
	public boolean getLowBatteryVibrate(){
		return preferences.getBoolean("LowBatteryVibrate", true);
	}
	
	
	
	/**
	 * low battery wain times
	 * 低电量报警次数
	 */
	public void saveLowBatteryWainTimes(int b){
		editor.putInt("LowBatteryWainTimes", b);
		editor.commit();
	}
	public int getLowBatteryWainTimes(){
		return preferences.getInt("LowBatteryWainTimes", 3);
	}
	
	/**
	 * low battery wain times
	 * 低电量记录时间
	 */
	public void saveLowBatteryLastTime(long  b){
		editor.putLong("LowBatteryLastTime", b);
		editor.commit();
	}
	public Long getLowBatteryLastTime(){
		return preferences.getLong("LowBatteryLastTime", 0);
	}
	/*****************************************lost device wain**********************************************/
	/**
	 * not distub
	 * 勿扰功能
	 * @param b
	 */
	public void saveDisturbWainAction(boolean b){
		editor.putBoolean("DisturbWainAction", b);
		editor.commit();
	}
	public boolean getDisturbWainAction(){
		return preferences.getBoolean("DisturbWainAction", false);
		
	}
	/**
	 * 近距离(0)、中距离(1)、远距离报警(2)
	 */
	public void saveDeviceRingFarNearAction(int  num){
		editor.putInt("DeviceRingFarNearAction", num);
		editor.commit();
	}
	public int getDeviceRingFarNearAction(){
		return preferences.getInt("DeviceRingFarNearAction", 2);
		
	}
	/**
	 * 设备寻找手机方式：二击：0，三击：1
	 */
	public void saveDeviceFindPhoneType(int type){
		editor.putInt("DeviceFindPhoneType", type);
		editor.commit();
	}
	public int getDeviceFindPhoneType(){
		return preferences.getInt("DeviceFindPhoneType", 0);
		
	}
	/**
	 * 减少误报 ：开：true 关：false 
	 * 默认：关
	 */
	public void saveReduceFalsePositives(boolean b){
		editor.putBoolean("ReduceFalsePositives", b);
		editor.commit();
	}
	public boolean getReduceFalsePositives(){
		return preferences.getBoolean("ReduceFalsePositives", false);
		
	}
	/**
	 * lost device wain times
	 * 防丢报警次数:1,3,5
	 */
	public void saveLostDeviceWainTimes(int n){
		editor.putInt("LostDeviceWainTimes", n);
		editor.commit();
	}
	public int getLostDeviceWainTimes(){
		return preferences.getInt("LostDeviceWainTimes", 3);
		
	}
	
	/**
	 *  报警模式:音乐（0），震动（1），音乐+震动（2）
	 */
	public void saveDeviceRingType(int type){
		editor.putInt("DeviceRingType", type);
		editor.commit();
	}
	public int getDeviceRingType(){
		return preferences.getInt("DeviceRingType", 0);
		
	}
	/**
	 * save bell
	 * @return
	 */
	/**
	 * 防丢报警音乐路径
	 */
	public void saveLostDeviceWainVoicePath(String str){
		editor.putString("LostDeviceWainVoicePath", str);
		editor.commit();
	}
	public String getLostDeviceWainVoicePath() {
		return preferences.getString("LostDeviceWainVoicePath","android.resource://" + mContext. getPackageName()
				+ "/" + R.raw.bird);
	}
	/**
	 * 防丢报警音乐名字
	 * @param str
	 */
	public void saveLostDeviceWainVoiceTitle(String str){
		editor.putString("LostDeviceWainVoiceTitle", str);
		editor.commit();
	}
	public String getLostDeviceWainVoiceTitle(){
		return preferences.getString("LostDeviceWainVoiceTitle",mContext.getString(R.string.default_music));
		
	}
	/**
	 * box wain light function 
	 * 箱包警示灯开关
	 */
	public void saveBoxWainLightIsOn(boolean b){
		editor.putBoolean("BoxWainLightIsOn", b);
		editor.commit();
	}
	public boolean getBoxWainLightIsOn(){
		return preferences.getBoolean("BoxWainLightIsOn", false);
		
	}
	
	/**********************************************************************/
	/**
	 * 指纹密码选择
	 */
	public void saveFingerPrintPwdCheck(boolean b){
		editor.putBoolean("FingerPrintPwdCheck", b);
		editor.commit();
	}
	public boolean getFingerPrintPwdCheck(){
		return preferences.getBoolean("FingerPrintPwdCheck", false);
		
	}
	
	/**
	 * 手势密码
	 */
	public void saveGesturePwdCheck(boolean b){
		editor.putBoolean("GesturePwdCheck", b);
		editor.commit();
	}
	public boolean getGesturePwdCheck(){
		return preferences.getBoolean("GesturePwdCheck", false);
		
	}
	/**
	 * 密码输入错误铃声
	 */
	public void saveWrongPwdWainVoicePath(String str){
		editor.putString("WrongPwdWainVoicePath", str);
		editor.commit();
	}
	public String getWrongPwdWainVoicePath(){
		return preferences.getString("WrongPwdWainVoicePath","android.resource://" + mContext. getPackageName()
				+ "/" + R.raw.cat);
	}
	
	/**
	 * 密码输入错误铃声
	 */
	public void saveWrongPwdWainVoiceTitle(String str){
		editor.putString("WrongPwdWainVoiceTitle", str);
		editor.commit();
	}
	public String getWrongPwdWainVoiceTitle(){
		return preferences.getString("WrongPwdWainVoiceTitle",mContext.getString(R.string.default_music));
	}
	
	/**
	 * 密码输入错误铃声
	 */
	public void saveWrongPwdWain(boolean b){
		editor.putBoolean("WrongPwdWain", b);
		editor.commit();
	}
	public boolean getWrongPwdWain(){
		return preferences.getBoolean("WrongPwdWain", false);
	}
	/**
	 * 箱包锁定时间
	 * @param num
	 */
	public void saveDeviceLockTimes(int num){
		editor.putInt("DeviceLockTimes", num);
		editor.commit();
	}
	
	public int getDeviceLockTimes(){
		int time=preferences.getInt("DeviceLockTimes", 0);
		if(time>2){
			time =0;
		}
		return time;
		
	}
	
	
	public void saveImageBFilePath(String path) {
		editor.putString("ImageBFilePath", path);
		editor.commit();
	}

	public String getImageBFilePath() {
		return preferences.getString("ImageBFilePath","");//
	}


	public void saveImageAFilePath(String path) {
		editor.putString("ImageAFilePath", path);
		editor.commit();
	}

	public String getImageAFilePath() {
		return preferences.getString("ImageAFilePath","");//
	}
	
	public void saveAPPVersionCode(int code ){
		editor.putInt("APPVersionCode", code);
		editor.commit();
	}
	
	public int getAPPVersionCode() {
		return preferences.getInt("APPVersionCode", 0);//
	}
	public boolean getNeedShowOADCaution() {

		return preferences.getBoolean("NeedShowOADCaution", true);
	}

	public void setNeedShowOADCaution(boolean flag) {
		editor.putBoolean("NeedShowOADCaution", flag);
		editor.commit();
	}
	
	
	public void saveLowBatteryWarnningDuration(int duration){
		editor.putInt("LowBatteryWarnningDuration", duration);
		editor.commit();
	}
	public int getLowBatteryWarnningDuration(){
		return preferences.getInt("LowBatteryWarnningDuration",10);
		
	}

	public void savaBoolen(String tag,Boolean value){
		editor.putBoolean(tag,value);
		editor.commit();
	}
	public boolean getBoolen(String tag) {
        return preferences.getBoolean(tag, false);
    }
}
